
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Markdown实时编辑器</title>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/github.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            height: 100vh;
            display: flex;
            flex-direction: column;
        }
        .header {
            background: #2c3e50;
            color: white;
            padding: 15px;
            text-align: center;
            font-size: 1.2rem;
        }
        .container {
            display: flex;
            flex: 1;
            overflow: hidden;
        }
        .editor-pane, .preview-pane {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            height: 100%;
        }
        .editor-pane {
            background: #f8f9fa;
            border-right: 1px solid #ddd;
        }
        .preview-pane {
            background: white;
        }
        #editor {
            width: 100%;
            height: 100%;
            min-height: 300px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            resize: none;
            font-family: monospace;
            font-size: 14px;
            line-height: 1.5;
        }
        #preview {
            height: 100%;
            overflow-y: auto;
            padding: 10px;
        }
        .markdown-body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            line-height: 1.6;
            color: #333;
        }
        .markdown-body h1, .markdown-body h2 {
            padding-bottom: 0.3em;
            border-bottom: 1px solid #eaecef;
        }
        .markdown-body pre {
            background-color: #f6f8fa;
            border-radius: 3px;
            padding: 16px;
            overflow: auto;
        }
    </style>
</head>
<body>
    <div class="header">Markdown实时编辑器</div>
    <div class="container">
        <div class="editor-pane">
            <textarea id="editor" placeholder="输入Markdown内容..."># Hello Markdown
## 功能特性
- 实时预览
- 代码高亮
- 响应式布局</textarea>
        </div>
        <div class="preview-pane">
            <div id="preview" class="markdown-body"></div>
        </div>
    </div>
    <script>
        const editor = document.getElementById('editor');
        const preview = document.getElementById('preview');
        
        // 配置marked
        marked.setOptions({
            highlight: function(code, lang) {
                const language = hljs.getLanguage(lang) ? lang : 'plaintext';
                return hljs.highlight(code, { language }).value;
            },
            breaks: true,
            gfm: true
        });

        // 实时渲染函数
        function render() {
            preview.innerHTML = marked.parse(editor.value);
        }

        // 初始化渲染
        render();

        // 监听输入事件
        editor.addEventListener('input', render);
    </script>
</body>
</html>
